package com.bdqn.service.Impl;

import com.bdqn.dao.DepartmentDao;
import com.bdqn.dao.Impl.DepartmentDaoImpl;
import com.bdqn.entity.CheckWork;
import com.bdqn.entity.DepInfo;
import com.bdqn.entity.Department;
import com.bdqn.entity.PageBean;
import com.bdqn.service.DepartmentService;

import java.util.List;

public class DepartmentServiceImpl implements DepartmentService {
    private DepartmentDao dao = new DepartmentDaoImpl();


    @Override
    public List<DepInfo> findDepCount() {
        return dao.findEmpCount();
    }

    @Override
    public PageBean<CheckWork> pageQuery(int depId, String like_name, int currentPage, int pageSize) {
        PageBean<CheckWork> pb = new PageBean<>();
        pb.setCurrentPage(currentPage);
        pb.setPageSize(pageSize);
        int totalCount = dao.findCount(depId,like_name);
        pb.setTotalCount(totalCount);
        int totalPage = totalCount%pageSize==0 ?totalCount/pageSize:(totalCount/pageSize)+1;
        pb.setTotalPage(totalPage);
        int offset = (currentPage-1)*pageSize;
        pb.setList(dao.findByPage(depId,like_name,offset,pageSize));
        return pb;
    }

    @Override
    public List<Department> findAll() {
        return dao.findAllDep();
    }
}
